<%@ page language="java" contentType="text/html; charset=utf-8" %>
<jsp:useBean id="rs" class="weaver.conn.RecordSet" scope="page"/>
<jsp:useBean id="bb" class="weaver.general.BaseBean"/>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="com.engine.workflow.biz.publicApi.RequestOperateBiz" %>
<%@ page import="com.engine.workflow.biz.workflowCore.RequestBaseBiz" %>
<%@ page import="com.engine.workflow.entity.core.RequestInfoEntity" %>
<%@ page import="com.engine.workflow.entity.publicApi.ReqOperateRequestEntity" %>
<%@ page import="com.engine.workflow.entity.requestForm.ReqFlowFailMsgEntity" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="weaver.hrm.User" %>
<%
    JSONObject jsonData = new JSONObject();
    int requestid = Util.getIntValue( request.getParameter( "requestid" ) );
    int curuserid = Util.getIntValue( request.getParameter( "userid" ) );
    int curnodeid = Util.getIntValue( request.getParameter( "nodeid" ) );
    boolean flag = false;
    String sql = "select max(concat(operatedate,' ',operatetime)),logid,nodeid,receivedpersonids,remark from workflow_requestlog where requestid=? and logtype='h'";
    rs.executeQuery( sql, requestid );
    rs.next();
    String logid = Util.null2String( rs.getString( "logid" ) );
    if (!"".equals( logid )) {
        int nodeid = Util.getIntValue( rs.getString( "nodeid" ) );
        int receivedpersonids = Util.getIntValue( rs.getString( "receivedpersonids" ) );
        String remark = Util.null2String( rs.getString( "remark" ) );
        if (!(curuserid == receivedpersonids && curnodeid == nodeid)) {
             flag = true;
            ReqOperateRequestEntity reqOperateRequestEntity = new ReqOperateRequestEntity();
            reqOperateRequestEntity.setEnableIntervenor( true );//是否执行节点前附加操作
            reqOperateRequestEntity.setIntervenorid( receivedpersonids + "" );//干预节点接收人，多个人以","号隔开
            reqOperateRequestEntity.setRemark( remark );//操作意见
            reqOperateRequestEntity.setRequestId( requestid );//要干预的流程请求Id
            reqOperateRequestEntity.setSignType( 1 );//会签类型 0 ：非会签 1：会签 2：依次逐个处理
            reqOperateRequestEntity.setSubmitNodeId( nodeid );//目标节点ID
            User user = new User();
            ReqFlowFailMsgEntity reqFailMsg = new ReqFlowFailMsgEntity();
            RequestInfoEntity reqInfo = RequestBaseBiz.loadRequestInfo( requestid );
            reqInfo.setSrc( "intervenor" );
            boolean isflag = RequestOperateBiz.flowNextNode( reqInfo, user, reqOperateRequestEntity, reqFailMsg );
            jsonData.put( "status", isflag );
        }
    }

    jsonData.put( "flag", flag );
    out.print( jsonData.toJSONString() );
    bb.writeLog( "getInvoice_Ajax=" + jsonData.toJSONString() );
%>
